package com.yi.mall.goods.controller;

import com.yi.mall.common.model.SkuInfo;
import com.yi.mall.common.utils.ResponseEnum;
import com.yi.mall.common.utils.Result;
import com.yi.mall.common.model.DTO.StockDTO;
import com.yi.mall.goods.service.impl.SkuInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author zzy
 * @since 2025-07-10
 */
@RestController
@RequestMapping("/skuInfo")
public class SkuInfoController {
    @Autowired
    private SkuInfoServiceImpl skuInfoService;
    @PostMapping("/dcount")
    public Result dcount(@RequestBody List<StockDTO> stock) throws Exception {
        try {
            skuInfoService.dcount(stock);
        } catch (Exception e) {
            return Result.fail(ResponseEnum.FAIL, "扣减库存失败");
        }
        return Result.success(ResponseEnum.SUCCESS);

    }
    @GetMapping( "/listAll")
    public Result listAll(){
        List<SkuInfo> skuInfos = skuInfoService.list();
        return Result.success(ResponseEnum.SUCCESS,skuInfos);
    }

}
